{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "italian-straight",
   "metadata": {},
   "source": [
    "# Problem 14.04 Heat Effect Upon Mixing of Methane and Dodecane at Elevated Temperature and Pressure Using SRK"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "statutory-consensus",
   "metadata": {},
   "source": [
    "1600 kg/hr of methane is mixed with 170 kg/hr of dodecane. The inlet temperature of both streams is 160 °C, and each enter at a pressure of 2 MPa. The mixing process is isobaric.\n",
    "What is the temperature of the combined stream? Use the SRK EOS with no binary interaction parameters."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "double-laundry",
   "metadata": {},
   "source": [
    "## Solution\n",
    "\n",
    "This is a straightforward calculation. The energy of both streams is combined; and the outlet pressure is known. The calculation only requires calculating the inlet energy of both streams, adding it up, and finding the mole fractions of the outlet."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "russian-endorsement",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The outlet temperature is 150.0933 °C\n"
     ]
    }
   ],
   "source": [
    "from thermo import ChemicalConstantsPackage, SRKMIX, FlashVL, CEOSLiquid, CEOSGas\n",
    "from chemicals import ws_to_zs, mixing_simple\n",
    "\n",
    "constants, correlations = ChemicalConstantsPackage.from_IDs(['methane', 'dodecane'])\n",
    "eos_kwargs = dict(Tcs=constants.Tcs, Pcs=constants.Pcs, omegas=constants.omegas)\n",
    "liquid = CEOSLiquid(SRKMIX, HeatCapacityGases=correlations.HeatCapacityGases, eos_kwargs=eos_kwargs)\n",
    "gas = CEOSGas(SRKMIX, HeatCapacityGases=correlations.HeatCapacityGases, eos_kwargs=eos_kwargs)\n",
    "flasher = FlashVL(constants, correlations, liquid=liquid, gas=gas)\n",
    "\n",
    "P1 = P2 = 2e6\n",
    "T1 = 160+273.15\n",
    "\n",
    "ws = [1600, 170]\n",
    "zs = ws_to_zs(ws=ws, MWs=constants.MWs)\n",
    "\n",
    "methane_H = flasher.flash(T=T1, P=P1, zs=[1, 0]).H()\n",
    "dodecane_H = flasher.flash(T=T1, P=P1, zs=[0, 1]).H()\n",
    "H = zs[0]*methane_H + zs[1]*dodecane_H\n",
    "\n",
    "res = flasher.flash(P=P2, H=H, zs=zs)\n",
    "print(f'The outlet temperature is {res.T-273.15:.4f} °C')"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
